﻿using System.IO;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace t_IntegratedTests
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class t_PPTRendering
    {
        public t_PPTRendering()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        [TestInitialize]
        public void TestSetup()
        {
            t_TestingLibrary.Utilities.MyClassInit();
        }

        [TestCleanup]
        public void TestCleanup()
        {
            t_TestingLibrary.Utilities.MyClassDone();
        }

        [TestMethod]
        [DeploymentItem("french.ppt")]
        public void TestFrenchPPTFile()
        {
            FileInfo f = new FileInfo("french.ppt");
            RenderPPT(f, 48, "TestFrenchPPTFile");
        }

        /// <summary>
        /// Render a ppt, and chekc the # of pages
        /// </summary>
        /// <param name="f"></param>
        /// <param name="p"></param>
        private void RenderPPT(FileInfo pptFile, int expectedPages, string testName)
        {
            ///
            /// Get the test file all copied over!
            /// 

            Assert.IsTrue(pptFile.Exists, "Test file does't exist");
            DirectoryInfo i = new DirectoryInfo(testName);
            if (i.Exists)
            {
                i.Delete(true);
            }
            i.Create();
            FileInfo testFile = new FileInfo(i.FullName + "\\" + pptFile.Name);
            pptFile.CopyTo(testFile.FullName);

            ///
            /// Setup the rendering stuff now
            /// 

            t_TestingLibrary.Utilities.AddPart(new GSRender.RenderUsingGS());
            t_TestingLibrary.Utilities.AddPart(new PowerPointRender.RenderUsingPowerPoint());
            t_TestingLibrary.Utilities.AddPart(new SimpleFileRendering.JPEGFileRender());
            t_TestingLibrary.Utilities.AddPart(new RenderEngine.LayoutHelper());
            t_TestingLibrary.Utilities.AddPart(new t_TestingLibrary.TestLogger());
            var rc = new RenderEngine.RenderControl();
            t_TestingLibrary.Utilities.Compose(rc);

            var v = rc.Render(testFile);
            Assert.IsNotNull(v, "Expected some visual back from that rendering!");
            Assert.AreEqual(expectedPages + 1, v.SGNodeList.Count(), "Incorrect # of slides found!");
        }
    }
}
